<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.bootcdn.net/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
    <title>Document</title>
    <style>
        li {
            width: 350px;
            height: 40px;
            border-bottom: 1px solid black;
        }
    </style>
</head>

<body>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>
        <li>9</li>
        <li>10</li>
    </ul>
    <script>
        const oLis = document.querySelectorAll('li')


        function enterHandle() {
            console.log(111);
            this.style.backgroundColor = 'yellowgreen'
        }

        function leaveHandle() {
            console.log(222);
            this.style.backgroundColor = ''
        }

        //  _.throttle(节流核心函数，时间，{leading:默认为true,})


          // 优化：用个变量接收节流函数 让每个函数都绑定这个变量 这样触发每个元素时就会调用同一个变量 就能实现节流的目的

          const transenter = _.throttle(enterHandle, 30, {
                leading: true,
                trailing: false
            })
            const transleave = leaveHandle

        oLis.forEach(item => {

            // // 此时给多个元素都绑定节流函数 触发每个元素时就会调用节流函数 没有达到节流的目的

            // item.onmouseenter = _.throttle(enterHandle, 1000, {
            //     leading: true,
            //     trailing: false
            // })
            // item.onmouseleave = _.throttle(leaveHandle, 1000, {
            //     leading: true,
            //     trailing: true
            // })

            item.onmouseenter = transenter
            item.onmouseleave = transleave
        })
    </script>
</body>

</html>